package com.personal.controller;

import com.personal.controller.result.BackCode;
import com.personal.controller.result.Result;
import com.personal.domain.Servicer;
import com.personal.service.ServiceService;
import com.personal.util.partDisplay.ServicerPart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.controller
 * @className: ServicerController
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/10 10:34
 * @version: 1.0
 */


@RestController
@RequestMapping("/servicer")
public class ServicerController {

    @Autowired
    private ServiceService serviceService;

    @GetMapping("/All")
    public Result selectAll(){
        List<Servicer> list=serviceService.selectAll();
        return new Result(list!=null? BackCode.GET_OK:BackCode.GET_ERR,list);
    }

    @GetMapping()
    public Result selectPartAll(){
        List<ServicerPart> list=serviceService.selectPartAll();
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }

    @GetMapping("/search")
    public Result selectPartByKey(@RequestParam("name")String name,@RequestParam("code")String code){
        List<ServicerPart> list=serviceService.selectPartByKey(name,code);
        return new Result(list!=null?BackCode.GET_OK:BackCode.GET_ERR,list);
    }

    @PostMapping()
    public Result add(@RequestBody Servicer servicer){
        boolean flag=serviceService.add(servicer);
        return new Result(flag?BackCode.SAVE_OK:BackCode.SAVE_ERR,flag);
    }


    @GetMapping("/updateData")
    public Result getUpdateData(@RequestParam("id") int id){
        Servicer servicer=serviceService.getUpdateData(id);
        return new Result(servicer!=null?BackCode.GET_OK:BackCode.GET_ERR,servicer);
    }
    @PutMapping()
    public Result update(@RequestBody Servicer servicer){
        boolean flag=serviceService.update(servicer);
        return new Result(flag?BackCode.UPDATE_OK:BackCode.UPDATE_ERR,flag);
    }


    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        boolean flag=serviceService.delete(ids);
        return new Result(flag?BackCode.DELETE_OK:BackCode.DELETE_ERR,flag);
    }




}
